Accessing rails flash[:notice] in a model

Posted by titaniumdecoy on Stack Overflow See other posts from Stack Overflow or by titaniumdecoy
Published on 2010-04-23T20:55:12Z Indexed on 2010/04/24 2:23 UTC
Read the original article Hit count: 289

I am trying to assign a message to flash[:notice] in a model observer.

This question has already been asked: Ruby on Rails: Observers and flash[:notice] messages?

However, I get the following error message when I try to access it in my model:

undefined local variable or method `flash' for #<ModelObserver:0x2c1742c>

Here is my code:

class ModelObserver < ActiveRecord::Observer
  observe A, B, C

  def after_save(model)
    puts "Model saved"
    flash[:notice] = "Model saved"
  end
end

I know the method is being called because "Model saved" is printed to the terminal.

Is it possible to access the flash inside an observer, and if so, how?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about rails-flash